
#----------------- 此Makefile 将多个-单独的c/cpp/cc文件，编译为各个可执行文件
# $ make -f Makefile_multi_2_multi_Out


#------------------文件后缀 ------------------
# .o文件
SrcSuf      = c
SrcSuf2     = cpp
SrcSuf3     = cc
ObjSuf      = o
LibSuf      = so
LibSuf2     = a
.SUFFIXES: 	.$(SrcSuf) .$(SrcSuf2) .$(SrcSuf3) \
			.$(ObjSuf) .$(LibSuf)  .$(LibSuf2) 
#------------------源文件 目标文件 可执行文件------------------

OBJFILES    +=  test_getopt.$(ObjSuf) 
# OBJFILES    +=  test_getopt_long.$(ObjSuf) 
# OBJFILES    +=  test_getopt_1.$(ObjSuf) 
OBJFILES    +=  test_getopt_2.$(ObjSuf) 
# OBJFILES    +=  test_getopt2.$(ObjSuf) 
# OBJFILES    +=  1.$(ObjSuf) 

target		=  $(OBJFILES:.o=.out)


#------------------编译选项 ------------------
# 头文件目录
INCLUDEPATH += 	-I /usr/include/ 
INCLUDEPATH +=	-I /usr/local/include 
# C编译选项
CFlag 	+= $(INCLUDEPATH) -w -g -ggdb -fshort-wchar  -std=c11 
# CFlag 	+= -D _POSIX_SOURCE

CppFlag += $(INCLUDEPATH) -w -g -ggdb -fshort-wchar  -std=c++11 
CxxFlag += $(INCLUDEPATH) -w -g -ggdb -fshort-wchar  -std=c++11 
#------------------链接选项 ------------------
# lib的路径
LIBPATH +=  -L /usr/lib/ 
LIBPATH +=	-L /usr/local/lib/     	 
# 动态库(libxxx.so)名称
LDLIBS 	+= 	-lpthread 
LDLIBS 	+= 	-lc
# 链接选项		
LDFLAGS +=  $(LIBPATH) 
LDFLAGS += 	$(LDLIBS)	
#------------------ ------------------
CC          =   gcc
CPP			=   g++
CXX 		=   g++
all: $(target) clean	

#------------------生成可执行文件 ------------------ 	
$(target):$(OBJFILES)
	@echo "creating $@ start..."
	$(CC)  $(LDFLAGS) $^ -o $@
	@echo "creating $@ end"

#------------------ .c 生成 .o 文件
.$(SrcSuf).$(ObjSuf):
	@echo "Compiling $(EXECUTABLE) $<"
	$(CC) $(CFlag) -c $< -o $@ 
#------------------. cpp 生成 .o 文件
.$(SrcSuf2).$(ObjSuf):
	@echo "Compiling $(EXECUTABLE) $<"
	$(CXX) $(CppFLAGS) -c $< -o $@
#------------------ .cc 生成 .o 文件
.$(SrcSuf3).$(ObjSuf):
	@echo "Compiling $(EXECUTABLE) $<"
	$(CXX) $(CxxFLAGS) -c $< -o $@
#------------------

#---------------------------------------------------------
.PHONY:cleanobj
clean:
	rm -f *.o

.PHONY:cleanall
cleanall:
	rm -f $(EXECUTABLE) *.o *.a *.so *.out
#---------------------------------------------------------




